package cn.javadog.smartbreeding.record.config;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

import cn.javadog.smartbreeding.core.config.util.Ret;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.stereotype.Component;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * @author 余勇
 */
@Component
public class AccessDeniedHandler implements org.springframework.security.web.access.AccessDeniedHandler {

	@Override
	public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
		// 返回我们的自定义json
		ObjectMapper objectMapper = new ObjectMapper();
		Ret ret = Ret.fail("请求无效，token权限不够");
		response.getWriter().write(objectMapper.writeValueAsString(ret));
	}
}
